import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;

import java.util.Arrays;
import java.util.Locale;

public class Test2 {
    /*public static void main1(String[] args) {
        String str1 ="hello";
        String str2 = new String("hello");
        char[] chars = {'a','b'};
        String str3 = new String(chars);
        System.out.println(str1.length());
        System.out.println(str1);
        System.out.println(str3);
        String str4 = "";
        System.out.println(str4.isEmpty());//str4指向的对象当中没有任何数据
       *//* String str5 = null;
        System.out.println(str5.isEmpty());//str5代表不指向任何对象*//*
    }*/

    public static void main2(String[] args) {
        String str1 = new String("hello");
        String str2 = new String("hello");
        System.out.println(str1==str2);//存储的值是否一样//地址
        System.out.println(str1.equals(str2));
        String str3 = "abc";
        String str4 = "abc";
        System.out.println(str3 == str4);//存的是同一个对象的地址
        String str5 = "abcdef";
        String str6 = "abd";
        System.out.println(str5.compareTo(str6));
        System.out.println(str5.compareToIgnoreCase(str6));
    }

    public static void main3(String[] args) {
        String str1 = "hello";
        char ch = str1.charAt(1);
        System.out.println(ch);
        System.out.println(str1.indexOf('l'));
        System.out.println(str1.indexOf('l',1));
        System.out.println(str1.indexOf("ll"));

        System.out.println(str1.lastIndexOf('l'));
        System.out.println(str1.indexOf('l',2));
    }

    public static void main4(String[] args) {
        String str1 = String.valueOf(1234);
        System.out.println(str1);

        String s2 = String.valueOf(new Person("zhangshan",18));
        System.out.println(s2);

        int data1 = Integer.valueOf("123");
        System.out.println(data1);
        int data2 = Integer.parseInt("1234");
        System.out.println(data2);
    }


    public static void main5(String[] args) {
        String s1 = "hello";
        String ret = s1.toUpperCase();
        System.out.println(ret);
        //所有对String的修改都不是在原来值的基础上
        String s2 = "ABCD";
        System.out.println(s2.toLowerCase());
        String s3 = "helloworld";
        char[] array = s3.toCharArray();
        System.out.println(Arrays.toString(array));
        //格式化
        String ret2 = String.format("%d,%d",10,20);
        System.out.println(ret2);
    }

    public static void main6(String[] args) {
        String s1 = "abababababba";
        String ret = s1.replaceFirst("ab","ooo");
        System.out.println(ret);
        String s2 = "abababababba";
        String ret2 = s2.replaceAll("ab","ooo");
        System.out.println(ret2);
        String s3 = "abababababba";
        String ret3 = s3.replace("ab","ooo");
        System.out.println(ret3);
        String s4 = "abababababba";
        String ret4 = s4.replace('a','p');
        System.out.println(ret4);
    }

    public static void main7(String[] args) {
       /* String s1 = "hello world bit";
        String[] ret = s1.split(" ");
        for(int i = 0; i < ret.length;i++) {
            System.out.println(ret[i]);
        }*/

       /* String s2 = "hello world bit";
        String[] ret2 = s1.split("\\.");
        for(int j = 0; j < ret2.length;j++){
             System.out.println(ret2[j]);
        }*/

       /* String s3 = "name=zhangshan&age=18";
        String[] ret3 = s3.split("=|&");
        for(int j = 0; j < ret3.length;j++){
            System.out.println(ret3[j]);
        }*/

        //多次拆分
        /*String s3 = "name=zhangshan&age=18";
        String[] ret3 = s3.split("=&");
        for(int j = 0; j < ret3.length;j++){
            //System.out.println(ret3[j]);
            String[] strings = ret3[j].split("=");
            for(String s:strings){
                System.out.println(s);
            }
        }*/
    }/**/

    public static void main8(String[] args) {
        String str = "hello";
        String ret1 = str.substring(1);
        System.out.println(ret1);//截取指定位置开始的部分

        String str2 = "hello";
        String ret2 = str.substring(1,3);
        System.out.println(ret2);

        String ret3 = "  hee llo hhh  ";
        System.out.println(ret3.trim());
        System.out.println(ret3);
    }


    public static void main(String[] args) {
        final int[] array = {1,2,3,4};//不嫩修改这个引用的指向，能修改内容
        array[0] = 100;
        System.out.println(array[0]);
    }
}

class Person{
    public String name;
    public int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}